package main

import "fmt"

//8, 3, 2, 9, 4, 6, 10, 0
//----------------------------------
//0
//10
//6
//4
//9
//2
//3
//8

//冒泡排序
//底下的(前面的)泡如果比上面的(后面的)泡要大,就交换位置
func bubble_sort(a [8]int) [8]int {
  for i := 0; i < len(a); i++ {
    for j := 0; j < len(a) -i -1/*第一趟要比较len(a)-1,第二趟要比较len(a)-2次,...*/; j++ {
      if a[j] > a[j+1] {
        a[j],a[j+1] = a[j+1],a[j]
      }
    }
  }
  return a
}

func main() {
  var i [8]int = [8]int{8, 3, 2, 9, 4, 6, 10, 0}
  res := bubble_sort(i)
  fmt.Println(res) //[0 2 3 4 6 8 9 10]
}
